#include "head.h"

int ls(int netfd, char* nowPath){
    
    DIR* pdir = opendir(nowPath);
    if(pdir == NULL){
        printf("ls error pdir.\n");
        return -1;
    }

    train_t train;
    bzero(&train, sizeof(train));
    if(pdir == NULL){
    send(netfd, &train.length, sizeof(int), MSG_NOSIGNAL);
    }
    
    struct dirent* pdirent;
    while((pdirent = readdir(pdir)) != NULL){
        if(pdirent->d_name[0] == '.'){
            continue;    
        }
        strcat(train.data, pdirent->d_name);
        train.data[strlen(train.data)] = ' ';
    }
    train.length = strlen(train.data);
    send(netfd, &train, sizeof(int)+train.length, MSG_NOSIGNAL);
    closedir(pdir);
    return 0;
}
